Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update NextIndex function. #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

KAZYPinkSaurus
Copy link

I came across your article while reading this post. Thank you for the wonderful article!

I have made changes to ensure consistency with the current value.

Previously, the current value would continuously increase if there were no errors. However, if a problem occurred with the backend selected by GetNextPeer func, the current value would fall within the range of 0 <= current < len(s.backends).

		idx := i % len(s.backends)     // take an index by modding
		if s.backends[idx].IsAlive() { // if we have an alive backend, use it and store if its not the original one
			if i != next {
				atomic.StoreUint64(&s.current, uint64(idx)) // Forces the value to be in the range `0 <= current < 
			}
			return s.backends[idx]
		}

I believe current should not continuously increase but should rather stay within the range of 0 <= current < len(s.backends), which is why I made this change.

I hope my PR is helpful to you.

Copy link

stackblitz bot commented Aug 21, 2024

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant